package ii.zjf.week4.count;

import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;

public class Add6 extends BaseAdd {

    public static boolean addFinish = false;

    public static void main(String[] args) throws InterruptedException {

        ReentrantLock reentrantLock = new ReentrantLock();
        Condition condition = reentrantLock.newCondition();

        Thread thread = new Thread(() -> {
            try {
                reentrantLock.lock();
                count.add();
                addFinish = true;
                condition.signal();
            } finally {
                reentrantLock.unlock();
            }
        });

        thread.start();

        try {
            reentrantLock.lock();
            while (!addFinish) {
                condition.await();
            }
        } finally {
            reentrantLock.unlock();
        }

        System.out.println("success : " + count.getCount());

    }
}
